package debtbundler.domain.entity.impl;


import static org.junit.Assert.*;

import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import debtbundler.domain.entity.Person;
import debtbundler.domain.entity.SharedCost;

public class BalanceSheetTest {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		debtbundler.logging.ConfigurationReader.setDefaultConf();
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	
	/**
	 * Tests index swapping of persons and shared costs.
	 */
	@Test 
	public void testSwapping() {		
		BalanceSheetImpl sheet = new BalanceSheetImpl();
		sheet.addMoneyPool(new PersonImpl());
		sheet.addMoneyPool(new SharedCostImpl());
		sheet.addMoneyPool(new SharedCostImpl());
		sheet.addMoneyPool(new PersonImpl());
		sheet.addMoneyPool(new SharedCostImpl());
		sheet.addMoneyPool(new PersonImpl());
		
		List<Person> persons = sheet.getPersons();
		Person person0 = persons.get(0);
		Person person2 = persons.get(2);
		sheet.swapPersons(0, 2);
		persons = sheet.getPersons();
		assertEquals("Correct index after swapping", person0, persons.get(2));
		assertEquals("Correct index after swapping", person2, persons.get(0));
		
		
		List<SharedCost> costs = sheet.getSharedCosts();
		SharedCost cost0 = costs.get(0);
		SharedCost cost2 = costs.get(2);
		sheet.swapSharedCosts(0, 2);
		costs = sheet.getSharedCosts();
		assertEquals("Correct index after swapping", cost0, costs.get(2));
		assertEquals("Correct index after swapping", cost2, costs.get(0));
		
	}
}
